from rest_framework import serializers
from .models import *
from django.contrib.auth.hashers import make_password, check_password


class RegisterSer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

    def create(self, validated_data):
        # 调用django提供的密码加密方法
        validated_data["password"] = make_password(validated_data["password"])

        instace = User.objects.create(**validated_data)

        return instace
